package com.jumi.microservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jumi.microservice.entity.Comment;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Scw
 * @Date 2020-08-04 17:55
 */
@Mapper
public interface CommentMapper extends BaseMapper<Comment> {

    /**
     * 批量插入
     *
     * @param list
     * @return
     */
    @Insert("<script> INSERT INTO comment "
            + "(uid, gid,spu_gid, service_attitude, express_packaging, logistics_services, product_satisfaction, content, images, is_anonymous,is_images,is_repeat_customers,order_id)"
            + "VALUES "
            + "<foreach collection='list' item='comment' index='index' separator=',' >"
            + "(#{comment.uid},#{comment.gid},#{comment.spuGid},#{comment.serviceAttitude},#{comment.expressPackaging},#{comment.logisticsServices},#{comment.productSatisfaction},#{comment.content},#{comment.images},#{comment.isAnonymous},#{comment.isImages},#{comment.isRepeatCustomers},#{comment.orderId})" +
            "</foreach>"
            + "</script>")
    Integer batchInsertComment(List<Comment> list);

    /**
     * 更新评论spugid为回头客状态
     * @param idStr
     * @return
     */
    @Update("update comment set is_repeat_customers = 1 where spu_gid in ( ${idStr} ) ")
    Integer repeatUpdata(@Param("idStr") Integer idStr);

}
